package com.lsy.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lsy.entity.Index;
import com.lsy.service.IndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Long
 * @since 2022-02-26
 */
@RestController
//@RequestMapping("/index")
@CrossOrigin
public class IndexController {
    @Autowired
    private IndexService indexService;

    @RequestMapping("/index")
    public List<Index> getIndex() {
        List<Index> index = indexService.list();
        return index;
    }

    @GetMapping("/getByPage")
    public Page<Index> getByPage(@RequestParam(value = "current", required = true, defaultValue = "1") Integer current,
                                @RequestParam(value = "size", required = true, defaultValue = "2") Integer size) {
        Page<Index> page = new Page<>(current,size);
        Page<Index> indexPage = indexService.page(page);
        return indexPage;
    }

    @PostMapping("/update")
    public Boolean update(@RequestBody Index index) {
        boolean b = indexService.updateById(index);
        return b;
    }

    @PostMapping("/save")
    public Boolean save(@RequestBody Index index) {
        System.out.println(index.toString());
        boolean b = indexService.save(index);
        return b;
    }

    @DeleteMapping("/delete")
    public Boolean delete(Integer id) {
        boolean b = indexService.removeById(id);
        return b;
    }

    @GetMapping("/name")
    public String haha(){
        return "小龙Hibernation";
    }
}

